<template>
    <div class="share">
      <span @click="shareContent">向朋友分享app</span>
      <div v-if="shareError" class="error">{{ shareError }}</div>
    </div>
  </template>
  
  <script setup>
  import { ref } from 'vue';
  
  const shareError = ref("");
  
  const shareContent = async () => {
    if (navigator.share) {
      try {
        await navigator.share({
          title: '分享转发app',
          url: window.location.href,
        });
        console.log('分享成功！');
      } catch (error) {
        shareError.value = "分享失败: " + error.message;
      }
    } else {
      shareError.value = "该浏览器不支持分享功能";
    }
  };
  </script>
  
  <style scoped>
  .share {
    display: inline-block;
    margin-left: 20px;
    
  }
  
  .error {
    color: red;
    margin-top: 10px;
  }
  </style>
  